package com.mxy.myapplication.asynctask;

import android.os.AsyncTask;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import android.util.Log;


/**
 * 在异步线程中执行的handleMessage~
 */
public class MyAsyncTask extends AsyncTask<Integer, Integer, Integer> {

    private static class Myhandler extends Handler {

        private Myhandler(Looper looper) {
            super(looper);
        }

        @Override
        public void handleMessage(Message msg) {
            try {
                Log.i("异步线程中执行的Handler", "线程 handleMessage开始休眠");
                Thread.sleep(5000);
                Log.i("异步线程中执行的Handler", "线程 handleMessage休眠结束");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }


    @Override
    protected Integer doInBackground(Integer[] params) {
        HandlerThread handlerThread = new HandlerThread("this");
        handlerThread.start();

        Myhandler myhandler = new Myhandler(handlerThread.getLooper());
        myhandler.sendEmptyMessage(1);

        return null;
    }
}